package com.TP.www.servlet;

import com.TP.www.po.Appraise;
import com.TP.www.po.Customer;
import com.TP.www.po.Merchant;
import com.TP.www.service.AppraisePort;
import com.TP.www.service.impl.MerchantAppraise;

import java.util.List;

import static com.TP.www.constant.Constant.*;

/**
 * @author 邱彦祥
 * 评论界面
 */
public class AppraiseMenu {
    /**
     * 评论界面主函数
     * 用于分辨当前用户是顾客还是商家
     */
    public static void showAppraiseMain(){
        if( loginUser instanceof Customer){
            showCustomerAppraiseMenu();
        }else if(loginUser instanceof Merchant){
            showStoreAppraiseMenu();
        }
    }

    /**
     *客户评论界面
     */
    public static void showCustomerAppraiseMenu(){
        List<Appraise> appraises = AppraisePort.getAppraiseById(GET_APPRAISE_BY_CUSTOMER_ID, loginUser.getId());
        System.out.println("***********评论界面***********");
        if (!appraises.isEmpty()) {
            System.out.println(loginUser.getName() + "用户: 以下为您对店铺的评价!");
            for (Appraise appraise : appraises) {
                System.out.println("店铺名: " + appraise.getStoreName() + "评价: " + appraise.getContent());
            }
        } else {
            System.out.println(loginUser.getName() + "用户，当前无您的任何评价!");
            System.out.println("*******************************");
        }
        System.out.println("按任意键返回!");
        SYS_SC.nextLine();
    }

    /**
     * 店铺评论界面
     */
    public static void showStoreAppraiseMenu(){
        List<Appraise> appraises = AppraisePort.getAppraiseById(GET_APPRAISE_BY_MERCHANT_ID,loginUser.getId());
        int i = 1;
        System.out.println("***********评论界面***********");
        if (!appraises.isEmpty()) {
            System.out.println("以下为店铺的评价!");
            for (Appraise appraise : appraises) {
                System.out.println( i + " " +appraise.getName() + "用户评价: " + appraise.getContent());
                i++;
            }
        } else {
            System.out.println("当前无对店铺的任何评价!");
        }
        System.out.println("*******************************");
        int choose = AppraisePort.getChoose(i);
        if (choose != 0){
            new MerchantAppraise().removeAppraise(appraises.get(choose-1));
        }
    }
}
